//
//  NSObject+Graphic.m
//  LOOKPIC
//
//  Created by FISH on 2018/4/24.
//  Copyright © 2018年 yimindai. All rights reserved.
//

#import "NSObject+Graphic.h"
@implementation NSObject (Graphic)

-(NSMutableAttributedString*)setMutableAttributedString:(NSString*)text didMakeRange:(NSRange)range didMakeColor:(UIColor*)color
{
    NSDictionary *intDic=@{NSFontAttributeName:[UIFont systemFontOfSize:16.0],NSForegroundColorAttributeName:[UIColor blackColor]};
    NSMutableAttributedString *intAbuted = [[NSMutableAttributedString alloc]initWithString:text attributes:intDic];
    [intAbuted addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:14.0] range:range];//变小
    [intAbuted addAttribute:NSForegroundColorAttributeName value:color range:range];
    return intAbuted;
}

- (NSMutableAttributedString*)setMutableAttributedString:(NSString*)text didMakeImage:(UIImage*)image atIndex:(NSInteger)location didMakeBounds:(CGRect)rect
{
    NSDictionary *intDic = [NSDictionary dictionaryWithObjectsAndKeys:
                                   [UIFont systemFontOfSize:16.f],NSFontAttributeName,
                                   [UIColor blackColor],NSForegroundColorAttributeName,nil];
    NSMutableAttributedString *intAbuted = [[NSMutableAttributedString alloc] initWithString:text attributes:intDic];
    NSTextAttachment *textAttachment = [[NSTextAttachment alloc] init];
    textAttachment.image = image;  //设置图片源
    textAttachment.bounds = rect;//设置图片位置和大小
    // 将文字附件转换成属性字符串
    NSAttributedString *attachmentAttrStr = [NSAttributedString attributedStringWithAttachment:textAttachment];
    // 将转换成属性字符串插入到目标字符串
    [intAbuted insertAttributedString:attachmentAttrStr atIndex:location];
    return intAbuted;
}

- (NSMutableAttributedString*)setMutableAttributedString:(NSString*)text didInitialColor:(UIColor*)iniColor atIndexCurrentColor:(UIColor*)CurColor didMakeRange:(NSRange)range
{
    NSDictionary *intDic=@{NSFontAttributeName:[UIFont systemFontOfSize:14.0],NSForegroundColorAttributeName:iniColor};
    NSMutableAttributedString *muAttrString = [[NSMutableAttributedString alloc] initWithString:text attributes:intDic];
    NSMutableParagraphStyle *paragtaphStyle = [[NSMutableParagraphStyle alloc] init];
    paragtaphStyle.alignment = NSTextAlignmentCenter;
    paragtaphStyle.paragraphSpacing = 11.0;
    paragtaphStyle.paragraphSpacingBefore = 10.0;
    paragtaphStyle.headIndent = 0.0;
    paragtaphStyle.lineBreakMode = NSLineBreakByWordWrapping;
    NSDictionary *dic = @{
                          NSForegroundColorAttributeName:CurColor,
                          NSFontAttributeName:[UIFont systemFontOfSize:20.0],
                          NSParagraphStyleAttributeName:paragtaphStyle,
                          NSUnderlineStyleAttributeName:@(NSUnderlineStyleNone)
                          };
    [muAttrString setAttributes:dic range:range];
    return muAttrString;
}
@end
